package ibm.cognos.imt.template

import groovy.xml.MarkupBuilder

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 5/9/14
 * Time: 2:21 PM
 * To change this template use File | Settings | File Templates.
 */
class ListTemplate extends AbstractTemplate {
    ibm.cognos.imt.List list

    ListTemplate(ibm.cognos.imt.List l){
        list = l
    }

    @Override
    def generateTemplateSpec(MarkupBuilder builder) {
        builder.list(refQuery: "$list.queryName", horizontalPagination: "true", name: "$list.name", rowsPerPage: "$list.rowPerPage") {
            noDataHandler {
                contents {
                    block {
                        contents {
                            textItem {
                                dataSource {
                                    staticValue("No Data Available")
                                }
                                style {
                                    CSS(value: "padding:10px 18px;")
                                }
                            }
                        }
                    }
                }
            }
            style {
                defaultStyles {
                    defaultStyle(refStyle: "ls")
                }
                CSS(value: "border-collapse:collapse2")
            }
            listColumns ()
        }
    }

    @Override
    def getTemplateNode() {
        root = new XmlSlurper(false, false).parseText(getSpecStr())
        list.columns.each{
            root.listColumns.appendNode(new ListItemTemplate(it.getDataItem().name).getTemplateNode())
        }
        root
    }
}
